"""
Gauge
=====

This example shows how to use a `Gauge` in determinate mode (when you know what
the range will be).
"""
from wxpita import *

f = SizedFrame [
    SizedPanel(sizerType='horizontal') [
        Button(name='startBtn', label='Start'),
        Button(name='stopBtn', label='Stop'),
    ],
    
    Gauge(name='gauge', range=100, expand=True),

    TextCtrl(name='log', style='te_multiline', expand=True, proportion=1),
]

@f.Init
def _():
    def inc_gauge():
        if f.gauge.GetValue() < f.gauge.GetRange():
            f.gauge.SetValue(f.gauge.GetValue()+1)
            f.later.Restart(30)
        else:
            f.startBtn.Enable(True)
            f.startBtn.SetFocus()
            f.stopBtn.Enable(False)
            f.log.AppendText('Gauge stopped\n')

    f.later = wx.CallLater(1000, inc_gauge)
    f.startBtn.Enable(False)

@f.close
def _(evt):
    f.later.Stop()
    f.Destroy()

@f.startBtn.button_clicked
def _(evt):
    if f.gauge.GetValue() == f.gauge.GetRange():
        f.gauge.SetValue(0)
    f.later.Restart()
    f.startBtn.Enable(False)
    f.stopBtn.Enable(True)
    f.stopBtn.SetFocus()

    f.log.AppendText('Gauge started\n')

@f.stopBtn.button_clicked
def _(evt):
    f.later.Stop()
    f.stopBtn.Enable(False)
    f.startBtn.Enable(True)
    f.startBtn.SetFocus()

    f.log.AppendText('Gauge stopped\n')
    
f.Show('Gauge Example', size=(450,300))
